package me.hunche.app.service.impl;

import java.util.List;

import me.hunche.app.dao.ActivityMemberDao;
import me.hunche.app.dao.UserDao;
import me.hunche.app.domain.ActivityMember;
import me.hunche.app.service.ActivityMemberService;
import me.hunche.app.util.DateHelper;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.feinno.framework.common.service.EntityServiceImpl;

@Service("activityMemberService")
public class ActivityMemberServiceImpl extends EntityServiceImpl<ActivityMember, ActivityMemberDao> implements ActivityMemberService {
	
	@Autowired UserDao userDao;

	public List<ActivityMember> findByActivityId(Long activityId) {
		List<ActivityMember> list = getEntityDao().findByActivityId(activityId);
		if(list!=null && !list.isEmpty()){
			for(ActivityMember m:list){
				m.setUser(userDao.get(m.getUserId()));
			}
		}
		return list;
	}

	public void gone(ActivityMember activityMember) {
		if(!activityMember.hasGone()){
			activityMember.setGoneTime(DateHelper.now());
			getEntityDao().update(activityMember);
		}
	}

	public void ready(ActivityMember activityMember) {
		if(!activityMember.hasReady()){
			activityMember.setReadyTime(DateHelper.now());
			getEntityDao().update(activityMember);
		}
	}

}
